ostbuild: Add preserve_net config option
authorColin Walters <walters@verbum.org>
Tue, 13 Mar 2012 21:06:06 +0000 (17:06 -0400)
committerColin Walters <walters@verbum.org>
Tue, 13 Mar 2012 21:06:06 +0000 (17:06 -0400)
This is going to be necessary for the builder.

gnomeos/README-build.md
src/ostbuild/pyostbuild/buildutil.py
src/ostbuild/pyostbuild/builtin_build.py
src/ostbuild/pyostbuild/builtin_chroot_compile_one.py
src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py
src/ostbuild/pyostbuild/ostbuildrc.py

index 3a86b6093956ec78f6eadf202f68df2906f7f189..b432276d1b71d37180b38e7df46090002a432fc4 100644 (file)
@@ -14,7 +14,7 @@ dependency problems.
 At the end, the Yocto build process generates two tarballs: one for a
 base "runtime", and one "devel" with all of the development tools like
 gcc.  We then import that into an OSTree branch
-e.g. "bases/gnomeos-3.4-yocto-i686-devel".
+e.g. "bases/yocto/gnomeos-3.4-i686-devel".
 
 We also have a Yocto recipe "ostree-native" which generates (as you
 might guess) a native binary of ostree.  That binary is used to import
index 814e5e5783ec07ef52e187dc7d7f37b76c560cb0..96e0e40277f3ed3f7cc6f983fb059267adc4b28a 100755 (executable)
@@ -21,6 +21,7 @@ import urlparse
 import tempfile
 import StringIO
 
+from . import ostbuildrc
 from .subprocess_helpers import run_sync_get_output
 
 BUILD_ENV = {
@@ -141,3 +142,12 @@ def compose(repo, target, artifacts):
     revision = run_sync_get_output(child_args, log_initiation=True).strip()
     os.unlink(path)
     return revision
+
+def get_base_user_chroot_args():
+    path = find_user_chroot_path()
+    args = [path, '--unshare-pid', '--unshare-ipc']
+    if not ostbuildrc.get_key('preserve_net', default=False):
+        args.append('--unshare-net')
+    return args
+
+    
index 3603932798e8dff8aa4667933a4ec14ecedf798a..772aaca89100333c2eab67b490f013a675104b59 100755 (executable)
@@ -208,6 +208,7 @@ class OstbuildBuild(builtins.Builtin):
         parser = argparse.ArgumentParser(description=self.short_description)
         parser.add_argument('--skip-built', action='store_true')
         parser.add_argument('--recompose', action='store_true')
+        parser.add_argument('--skip-compose', action='store_true')
         parser.add_argument('--start-at')
         parser.add_argument('--shell-on-failure', action='store_true')
         parser.add_argument('--debug-shell', action='store_true')
@@ -255,7 +256,8 @@ class OstbuildBuild(builtins.Builtin):
             component = self.snapshot['components'].get(component_name)
             self._build_one_component(component_name, component)
 
-        for target in self.snapshot['targets']:
-            self._compose(target)
+        if not args.skip_compose:
+            for target in self.snapshot['targets']:
+                self._compose(target)
         
 builtins.register(OstbuildBuild)
index 40d46652f66993ecea11b31e7b665319379d58e3..fa29be99d5515efd15d5f6e923f85a9996c88e5a 100755 (executable)
@@ -23,6 +23,7 @@ import json
 from . import builtins
 from . import buildutil
 from . import fileutil
+from . import ostbuildrc
 from .ostbuildlog import log, fatal
 from .subprocess_helpers import run_sync, run_sync_get_output
 
@@ -128,16 +129,15 @@ class OstbuildChrootCompileOne(builtins.Builtin):
         
         chroot_sourcedir = os.path.join('/ostbuild', 'source', component_name)
 
-        ostbuild_user_chroot_path = buildutil.find_user_chroot_path()
-        
-        child_args = [ostbuild_user_chroot_path, '--unshare-pid', '--unshare-net', '--unshare-ipc',
-                      '--mount-readonly', '/',
-                      '--mount-proc', '/proc', 
-                      '--mount-bind', '/dev', '/dev',
-                      '--mount-bind', child_tmpdir, '/tmp',
-                      '--mount-bind', os.getcwd(), chroot_sourcedir,
-                      '--mount-bind', resultdir, '/ostbuild/results',
-                      '--chdir', chroot_sourcedir]
+        child_args = buildutil.get_base_user_chroot_args()
+        child_args.extend([
+                '--mount-readonly', '/',
+                '--mount-proc', '/proc', 
+                '--mount-bind', '/dev', '/dev',
+                '--mount-bind', child_tmpdir, '/tmp',
+                '--mount-bind', os.getcwd(), chroot_sourcedir,
+                '--mount-bind', resultdir, '/ostbuild/results',
+                '--chdir', chroot_sourcedir])
         if args.debug_shell:
             child_args.extend([rootdir, '/bin/sh'])
         else:
index bdee64c2455fbbddc145a20eb8e8e60ee53b0786..b94559961e4476d23b2395620e5993a084b627bf 100755 (executable)
@@ -35,15 +35,11 @@ class OstbuildChrootRunTriggers(builtins.Builtin):
         
         args = parser.parse_args(argv)
 
-        ostbuild_user_chroot_path = buildutil.find_user_chroot_path()
-
-        child_args = [ostbuild_user_chroot_path,
-                      '--unshare-pid', '--unshare-net', '--unshare-ipc',
-                      '--mount-proc', '/proc', 
-                      '--mount-bind', '/dev', '/dev',
-                      args.root,
-                      '/usr/bin/ostree-run-triggers']
-        print "%r" % (child_args,)
+        child_args = buildutil.get_base_user_chroot_args()
+        child_args.extend(['--mount-proc', '/proc', 
+                           '--mount-bind', '/dev', '/dev',
+                           args.root,
+                           '/usr/bin/ostree-run-triggers'])
         env_copy = dict(buildutil.BUILD_ENV)
         env_copy['PWD'] = '/' 
         run_sync(child_args, env=env_copy)
index 413f7f1f02d66a1f1a37fcee036f8bf9ba6eac65..a36febb7985a6bf3ce5700884ded9955940881a6 100755 (executable)
@@ -31,11 +31,22 @@ def get():
             _config[k.strip()] = v.strip()
     return _config
 
-def get_key(name, provided_args=None):
+# This hack is because we want people to be able to pass None
+# for "default", but still distinguish default=None from default
+# not passed.
+_default_not_supplied = object()
+def get_key(name, provided_args=None, default=_default_not_supplied):
+    global _default_not_supplied
     config = get()
     if provided_args:
         v = provided_args.get(name)
         if v is not None:
             return v
-    return config[name]
+    if default is _default_not_supplied:
+        # Possibly throw a KeyError
+        return config[name]
+    value = config.get(name, _default_not_supplied)
+    if value is _default_not_supplied:
+        return default
+    return value